package com.agentfactory.teleoreactive.compiler;

import java.util.LinkedList;
import java.util.List;

import com.agentfactory.logic.update.lang.AND;
import com.agentfactory.logic.update.lang.IFormula;
import com.agentfactory.teleoreactive.interpreter.Utilities;

public class SentenceBuilderVisitor implements TeleoReactiveParserVisitor {

	@Override
	public Object visit(SimpleNode node, Object data) {
//		System.out.print("Sentence Builder Visitor node ......"+node.toString()+" It's childrena are ");
//		for(int i = 0; i<node.jjtGetNumChildren();i++)System.out.print(node.jjtGetChild(i).toString()+", ");
//		if(0==node.jjtGetNumChildren()) System.out.print("No Children"); System.out.println();
		if (node.toString().equals("Condition")) {
			List<IFormula> list = new LinkedList<IFormula>();
			for (int i=0; i<node.jjtGetNumChildren(); i++) {
				String fos = "";
				SimpleNode litNode = (SimpleNode) node.jjtGetChild(i);
				if (litNode.jjtGetValue() != null) {
					fos += "~";
				}
				fos += new PredicateConstructorVisitor().visit((SimpleNode) litNode.jjtGetChild(0), null);
				list.add(Utilities.factory.createFormula(fos));
			}
			return new AND(list);
		}
		return null;
	}
}
